<template>
  <div>
    <div class="gl_searchBox gl_mb_15">
      <el-row :gutter="20">
        <el-col :md="6" :lg="4">
          <p>按所属机构选择</p>
          <el-select v-model="Api_GET_EventsManagementEntryCompetitionRegistersQO.DelegationId" size="mini" placeholder="全部" filterable @change="getPersonalData()">
            <el-option label="全部" value="" />
            <el-option v-for="item in mechanisms" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-col>
        <el-col :md="6" :lg="4">
          <p>状态</p>
          <el-select v-model="Api_GET_EventsManagementEntryCompetitionRegistersQO.ApproveStatusCode" size="mini" placeholder="全部" filterable @change="getPersonalData()">
            <el-option label="全部" value="" />
            <el-option v-for="item in dict.entryApproveStatus" :key="item.code" :label="item.value" :value="item.code" />
          </el-select>
        </el-col>
        <!-- 机构名称 -->
        <el-col :md="6" :lg="4">
          <p>选手名称/手机号</p>
          <el-input v-model="Api_GET_EventsManagementEntryCompetitionRegistersQO.Filter" placeholder="请输入" size="mini" clearable @change="getPersonalData()" />
        </el-col>
        <el-col :md="4" :lg="2">
          <!-- 查询按钮 -->
          <el-button style="margin-top:27px" type="primary" size="mini" @click="getPersonalData()">查询</el-button>
        </el-col>
      </el-row>
    </div>
    <el-row class="gl_mb_15">
      <el-col align="right">
        <el-button :loading="athleteLoading" type="warning" size="mini" @click="exportAthlete()">参报人员列表</el-button>
        <el-button :loading="groupLoading" type="warning" size="mini" @click="exportGroup()">参报机构统计</el-button>
        <el-button :loading="projectLoading" type="success" size="mini" @click="exportProject()">参报项目统计</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="tableData" stripe size="mini">
      <el-table-column type="index" width="50" align="center" />
      <el-table-column prop="imagePath" label="头像" width="90" align="center">
        <template slot-scope="{row}">
          <img v-if="row.imagePath" width="40" :src="getStaticFileUrl(row.imagePath)">
          <img v-else width="40" src="@/assets/images/person_default.png">
        </template>
      </el-table-column>
      <el-table-column prop="name" label="选手姓名" min-width="120" />
      <el-table-column prop="genderName" label="性别" width="60" align="center" />
      <el-table-column prop="phoneNumber" label="手机号" width="120" align="center" />
      <el-table-column prop="idCardNumber" label="证件号" width="160" align="center" />
      <el-table-column prop="delegationName" label="机构全称" />
      <el-table-column prop="delegationShortName" label="机构简称" align="center" />
      <el-table-column prop="entryApproveStatus.name" label="状态" />
    </el-table>

    <el-row class="gl_pt_20" style="text-align: center;">
      <el-pagination
        :current-page="Api_GET_EventsManagementEntryCompetitionRegistersQO.Page"
        :page-size="Api_GET_EventsManagementEntryCompetitionRegistersQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 50, 100]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import { api_GET_DownLoadFileAddHeader } from '@/extend/api/file';
import { errorText } from '@/lib';
import {
  api_GET_EventsManagementEntryEntryDeletations, // 获取机构下拉列表
  api_GET_EventsManagementEntryCompetitionRegisters // 获取参赛人员列表
} from '@/extend/api/gameswaggerApi/app.js';
import {
  Api_GET_EventsManagementEntryCompetitionRegistersQO
} from '@/lib/form/game/swaggerForm';
export default {
  name: 'Unconfirmed',
  data() {
    return {
      loading: false,
      athleteLoading: false,
      groupLoading: false,
      projectLoading: false,
      Api_GET_EventsManagementEntryCompetitionRegistersQO: new Api_GET_EventsManagementEntryCompetitionRegistersQO(),
      totalPage: 0,
      mechanisms: [], // 所属机构下拉列表
      tableData: []
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      tenantId: state => state.user.tenantId
    })
  },
  created() {
    this.getDict();
    this.getGroup(); // 获取机构下拉列表
    this.getPersonalData(); // 获取参赛人员
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    // 查询
    getPersonalData(page) {
      var that = this;
      that.loading = true;
      that.Api_GET_EventsManagementEntryCompetitionRegistersQO.Page = page || 1;
      that.Api_GET_EventsManagementEntryCompetitionRegistersQO.SkipCount = (that.Api_GET_EventsManagementEntryCompetitionRegistersQO.Page - 1) * that.Api_GET_EventsManagementEntryCompetitionRegistersQO.MaxResultCount;
      that.Api_GET_EventsManagementEntryCompetitionRegistersQO.CompetitionId = that.$route.params.id;
      that.Api_GET_EventsManagementEntryCompetitionRegistersQO.IncludeApproveStatus = true;
      api_GET_EventsManagementEntryCompetitionRegisters(that.Api_GET_EventsManagementEntryCompetitionRegistersQO).then(res => {
        that.tableData = res.items || [];
        that.totalPage = res.totalCount;
        that.loading = false;
      }, () => {
        that.loading = false;
        that.$message({ type: 'error', message: '获取个人明细失败！' });
      });
    },
    // 获取机构下拉列表
    getGroup() {
      const form = {
        CompetitionId: this.$route.params.id
      };
      api_GET_EventsManagementEntryEntryDeletations(form).then(res => {
        this.mechanisms = res;
      });
    },
    // 导出参报人员表
    exportAthlete() {
      var that = this;
      that.athleteLoading = true;
      const tempUrl = `/api/excel`;
      const fileName = '参报人员表' + '.xlsx';
      const params = {};
      params.ReportName = 'CompetitionEntryStatistics';
      const form = JSON.parse(JSON.stringify(that.Api_GET_EventsManagementEntryCompetitionRegistersQO));
      delete form.SkipCount;
      delete form.MaxResultCount;
      delete form.Page;
      params.GetCompetitionRegistersInput2 = JSON.stringify(form);
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, params).then(res => {
        that.athleteLoading = false;
      }).catch(error => {
        that.athleteLoading = false;
        errorText(error).then(function(text) {
          that.$message({ type: 'error', message: text });
        });
      });
    },
    // 导出参报机构表
    exportGroup() {
      var that = this;
      that.groupLoading = true;
      const tempUrl = `/api/excel`;
      const fileName = '参报机构表' + '.xlsx';
      const params = {};
      params.ReportName = 'OrganizationEntryStatistics';
      const form = JSON.parse(JSON.stringify(that.Api_GET_EventsManagementEntryCompetitionRegistersQO));
      delete form.SkipCount;
      delete form.MaxResultCount;
      delete form.Page;
      params.GetCompetitionRegistersInput2 = JSON.stringify(form);
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, params).then(res => {
        that.groupLoading = false;
      }).catch(error => {
        that.groupLoading = false;
        errorText(error).then(function(text) {
          that.$message({ type: 'error', message: text });
        });
      });
    },
    // 导出参报项目表
    exportProject() {
      var that = this;
      that.projectLoading = true;
      const tempUrl = `/api/excel`;
      const fileName = '参报项目表' + '.xlsx';
      const params = {};
      params.ReportName = 'CategoryEntryStatistics';
      const form = JSON.parse(JSON.stringify(that.Api_GET_EventsManagementEntryCompetitionRegistersQO));
      delete form.SkipCount;
      delete form.MaxResultCount;
      delete form.Page;
      params.GetCompetitionRegistersInput2 = JSON.stringify(form);
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, params).then(res => {
        that.projectLoading = false;
      }).catch(error => {
        that.projectLoading = false;
        errorText(error).then(function(text) {
          that.$message({ type: 'error', message: text });
        });
      });
    },
    // 图片回显
    getStaticFileUrl(relativeUrl) {
      if (!relativeUrl) return '';
      return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
    },
    // 分页
    sizeChange: function(MaxResultCount) {
      this.Api_GET_EventsManagementEntryCompetitionRegistersQO.MaxResultCount = MaxResultCount;
      this.getPersonalData();
    },
    pageIndexChange(currentPage) {
      this.getPersonalData(currentPage);
    }
  }
};
</script>

